package com.xiancheng;

public class SellTicket1 implements Runnable {
    private static int tickets = 100;

    @Override
    public void run() {
        sellTickets();
    }

    private static synchronized void sellTickets() {
        while (true) {
            if (tickets > 0) {
                try {
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "正在出售第" + tickets + "张票");
                tickets--;
            }
        }

    }
}
